package com.changli04._throw;

public class throwTest {
    public static void main(String[] args) {
        Student s1 = new Student();
//        s1.register(10);
//        s1 = new Student(-10);
        try{
            s1.register(-10);
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }
}
class Student {
    int id;

    public Student() {
    }

    public Student(int id) {
        this.id = id;
    }

//    public void register(int id) {
//        if (id < 0) {
//            throw new RuntimeException("输入的ID小于零");
//        }
//        this.id = id;
//    }
    public void register(int id) throws Exception {
        if (id < 0) {
            throw new Exception("输入的ID小于零");
        }
        this.id = id;
    }
}
